package org.abc.fund.controller.trade;

import org.abc.fund.controller.trade.response.SettlementResponse;
import org.abc.fund.entity.trade.Settlement;
import org.abc.fund.service.trade.SettlementService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/api/settlements")
public class SettlementController {

  private final SettlementService settlementService;

  public SettlementController(SettlementService settlementService) {
    this.settlementService = settlementService;
  }

  @GetMapping
  public ResponseEntity<List<SettlementResponse>> getSettlementsByOrderId(
      @RequestParam Long orderId) {
    List<Settlement> settlements = settlementService.getSettlementsByOrderId(orderId);
    List<SettlementResponse> response =
        settlements.stream().map(SettlementResponse::fromEntity).collect(Collectors.toList());
    return ResponseEntity.ok(response);
  }
}
